$(document).ready(function () {
    $('.easyui-accordion li a').click(function () {
        var tabTitle = $(this).text();
        var url = $(this).attr("href");
        addTab(tabTitle, url);
        $('.easyui-accordion li div').removeClass("selected");
        $(this).parent().addClass("selected");
        return false;
    }).hover(function () {
        $(this).parent().addClass("hover");
    }, function () {
        $(this).parent().removeClass("hover");
    });
    function loadOperationOrder(){
        $.post(Constant.ctx("/mulanweb/admin/order/getOperationOrder"),{},function(data){
            var html = $("#operationOrderModel").html();
            var compileHtml = Template7.compile(html);
            var lastHtml = compileHtml(data);
            $("#container").html(lastHtml);
            $("#operationOrder a").click(function(){
                var tabTitle = "未处理订单详情";
                var url = $(this).attr("href");
                addTab(tabTitle, url);
                return false;
            })
        });
    }
    function loadOperationVisaOrder(){
        $.post(Constant.ctx("/mulanweb/admin/visa_order/getOperationOrder"),{},function(data){
            var html = $("#operationOrderModel").html();
            var compileHtml = Template7.compile(html);
            var lastHtml = compileHtml(data);
            $("#container").html(lastHtml);
            $("#operationOrder a").click(function(){
                var tabTitle = "未处理订单详情";
                var url = $(this).attr("href");
                addTab(tabTitle, url);
                return false;
            })
        });
    }
    setTimeout(tt,5000);
    function tt (){
        loadOperationOrder();
        loadOperationVisaOrder();
        setTimeout(tt,5000);
    }

    function addTab(subtitle, url) {
        if (!$('#tabs').tabs('exists', subtitle)) {
            $('#tabs').tabs('add', {
                title: subtitle,
                content: createFrame(url),
                closable: true,
                width: $('#mainPanle').width() - 10,
                height: $('#mainPanle').height() - 300
            });
        } else {
            $('#tabs').tabs('close', subtitle);
            $('#tabs').tabs('add', {
                title: subtitle,
                content: createFrame(url),
                closable: true,
                width: $('#mainPanle').width() - 10,
                height: $('#mainPanle').height() - 300
            });
        }
    }

    function createFrame(url) {
        var mainFrame = "mainFrame_" + parseInt(Math.random() * Math.random() * 100);
        return '<iframe class="easyui-layout" data-options="fit:true"  name="'+mainFrame+'" marginheight="0" marginwidth="0" scrolling="no" frameborder="0" src="' + url + '"></iframe>';
    }
});